<template>
    <router-view></router-view>
</template>

<script>
    /* eslint-disable */
    import '@/assets/dist/css/mui.css'
    import '@/assets/css/main.css'
    import '@/assets/js/rem/flex'
    import {synCurrency, synWallet, synExchange} from '@/assets/js/timer/index';

    export default {
        name: 'app',
        data() {
            return {
                time: 60,
                timedone: "",
            }
        },
        created() {
            document.addEventListener("plusready", this.onPlusReady, false);
            synCurrency();
            synWallet();
            synExchange();
        },
        methods: {
            onPlusReady: function () {
                //设置沉浸式状态栏
                // plus.navigator.setStatusBarBackground('#FAFBFC');
                plus.navigator.setStatusBarStyle('dark');

                //监听app切换到后台运行，时间超过60秒则重新启动app，防止假死
                if ('Android' === plus.os.name) {
                    let th = this;
                    document.addEventListener('pause', function () {
                        if (!!th.timedone) {
                            clearTimeout(th.timedone);
                        }
                        localStorage.setItem("restTime", 60);
                        for (let i = 1; i <= localStorage.getItem('restTime'); i++) {
                            th.timedone = setTimeout(function () {
                                localStorage.setItem('restTime', (Number(localStorage.getItem('restTime')) - 1).toString());
                            }, i * 1000);
                        }
                    }, false);
                    document.addEventListener('resume', function () {
                        if (Number(localStorage.getItem("restTime")) === 0) {
                            plus.runtime.restart();
                        }
                    }, false);

                    // 监听安卓返回键
                    plus.key.addEventListener("backbutton", () => {
                        // “关于我们” 中打开了webview 窗口，返回需要退出此窗口
                        let ws = plus.webview.getWebviewById("about-me-link");
                        if (ws) {
                            ws.close();
                        }

                        if (this.backUrl == "") {
                            this.backRoute();
                        } else if (this.backUrl != "no") {
                            this.changeRoute(this.backUrl);
                        } else {
                            plus.runtime.quit();
                        }
                    });

                }
            },

        }
    }
</script>
